/**
 * Copyright (c) 2006, 2007, 2008 Marwan Abi-Antoun, Jonathan Aldrich, Nels E. Beckman,
 * Kevin Bierhoff, David Dickey, Ciera Jaspan, Thomas LaToza, Gabriel Zenarosa, and others.
 *
 * This file is part of Crystal.
 *
 * Crystal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Crystal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Crystal.  If not, see <http://www.gnu.org/licenses/>.
 */
package edu.cmu.cs.crystal.cfg.eclipse;

import org.eclipse.jdt.core.dom.ASTNode;

import att.grappa.Edge;
import att.grappa.Graph;
import att.grappa.Node;
import edu.cmu.cs.crystal.cfg.ICFGEdge;
import edu.cmu.cs.crystal.flow.ILabel;

public class EclipseCFGEdge implements ICFGEdge<ASTNode> {
	EclipseCFGNode sink;
	EclipseCFGNode source;
	ILabel label;

	EclipseCFGEdge(EclipseCFGNode source, EclipseCFGNode sink, ILabel label) {
		this.source = source;
		this.sink = sink;
		this.label = label;
	}

	public EclipseCFGNode getSink() {
		return sink;
	}

	public EclipseCFGNode getSource() {
		return source;
	}

	public String toString() {
		return getSource().toString() + "->" + getSink().toString();
	}

	public void addToGraph(Graph graph, Node source, Node sink) {
		Edge dotEdge = new Edge(graph, source, sink);
		dotEdge.setAttribute(Edge.LABEL_ATTR, label.getLabel());
	}

	public ILabel getLabel() {
		return label;
	}
}
